<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductImagesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        /**
         *   `id` int(11) NOT NULL AUTO_INCREMENT,
            `img_id` int(11) NOT NULL COMMENT '外键，关联图片表',
            `delete_time` int(11) DEFAULT NULL COMMENT '状态，主要表示是否删除，也可以扩展其他状态',
            `order` int(11) NOT NULL DEFAULT '0' COMMENT '图片排序序号',
            `product_id` int(11) NOT NULL COMMENT '商品id，外键',
         */
        Schema::create('product_images', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('img_id')->unsigned();
            $table->integer('order');
            $table->integer('product_id')->unsigned();

            $table->foreign('img_id')->references('id')->on('images')->onDelete('cascade');
            $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('product_images');
    }
}
